package com.cyq.dascma.handler.valida.impl;

import com.cyq.dascma.constant.ValidaEnum;
import com.cyq.dascma.entity.Student;
import com.cyq.dascma.exception.ServiceException;
import com.cyq.dascma.handler.valida.Valida;
import com.cyq.dascma.result.ResultGenerator;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import java.rmi.ServerException;

/**
 * dingwen
 * 2021/4/3 20:44
 **/
public class StudentValidaImpl implements Valida<Student> {


    @Override
    public void valida(ValidaEnum validaEnum, Student student) {
        if (ObjectUtils.isEmpty(student)) {
            throw new ServiceException(ResultGenerator.genFailureResult("student不能为空").setCode(400));
        }
        switch (validaEnum) {
            case LOGIN:
                if (!StringUtils.hasText(student.getStudentId())) {
                    throw new ServiceException(ResultGenerator.genFailureResult("学号[账号]不能为空").setCode(400));
                }
                if (!StringUtils.hasText(student.getStudentPassword())) {
                    throw new ServiceException(ResultGenerator.genFailureResult("密码不能为空").setCode(400));
                }
                break;
            case MODIFY:
                if (!StringUtils.hasText(student.getStudentId())) {
                    throw new ServiceException(ResultGenerator.genFailureResult("学号[账号]不能为空").setCode(400));
                }
        }
    }
}
